Page({
  data: {
    car: ""
  },
  onLoad: function (options) {
    var that = this;
    var session3rd = wx.getStorageSync("session3rd");
    wx.request({
      url: "https://myzhongchou.net/public/index.php/api/user/getlicense",
      data: {
        session3rd: session3rd
      }, header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          car: res.data.msg.license
        })
      }
    })
  },
  car: function (e) {
    var that = this;
    that.setData({
      car: e.detail.value
    })
  },
  button: function () {
    var that = this;
    var cars = that.data.car;
    var session3rd = wx.getStorageSync("session3rd");
    wx.request({
      url: "https://myzhongchou.net/public/index.php/api/user/insert_license",
      methods: "post",
      data: {
        session3rd: session3rd,
        license: cars        
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        if (res.data.success == 0) {
          wx.showToast({
            title: '提交成功',
            icon: 'success'
          })
          wx.switchTab({
            url: '../wode/wode'
          })
        } else if (res.data.error == 1) {
          wx.showToast({
            title: '车牌照格式错误',
            image: '../../img/gantan.png'
          })
        } else if (res.data.error == 2) {
          wx.showToast({
            title: '车牌号已存在',
            image: '../../img/gantan.png'
          })
        } else {
          wx.showToast({
            title: '网络错误，请稍后重试',
            image: '../../img/gantan.png'
          })
        }
      }
    })
  }
})